from ultralytics import YOLO

# Load a YOLOv8 model (e.g., yolov8n.pt)
model_name = "yolo11n"
model = YOLO(f"{model_name}.pt")

# Export the model to ONNX format
# opset=12 is recommended for compatibility
# simplify=True optimizes the model graph
# dynamic=False ensures fixed input size, often better for C++ deployment
# imgsz=640 sets the input image size
model.export(format="ncnn", opset=12, simplify=True, dynamic=False, imgsz=640)
print(f"Model exported successfully to {model_name}.ncnn")